#ifndef __MANAGER_H__
#define __MANAGER_H__

#include "com/MyThread.h"
#include "com/common.h"
#include "CmdChannel.h"
#include "MediaChannel.h"

typedef struct tagUploadFileInfo
{
	string	strFileName;
	string  strRemoteFilePath;
	int		nFileType;
	int		nIsSign;
	int		nUserId;
	string	strUserName;
}UploadFileInfo;

typedef void(*OnMessageCallback)(int nType, const char *pMsg, const int nMsgLen);

class CMyManager : public CMyThread
{
public:
	CMyManager(OnMessageCallback callback);
	~CMyManager(void);

	bool StartApp(int nTerminalId, const char *pSvrIp, unsigned short usPort);
	void Stop(void);

	char *GetSvrIp(void);
	unsigned short GetSvrPort(void);

	int	GetTerminalId(void);
	void PutRecvData(RecvDataInfo *pRecv);

	bool GetUserInfo(char *pOutBuf, int *len);
	bool GetUserList(char *pOutBuf, int *len);

	bool GetMeetingFileList(char *pOutBuf, int *len);
	bool GetMeetingIssueList(char *pOutBuf, int *len);

	bool GetMeetingVoteList(char *pOutBuf, int *len);
	int UserLogin(const char *pUserName, const char *pPassWord, char *outMsg, int *msgLen);

	bool UserSignControl(int nControlType);
	bool AllUserSign(const char *pJson);

	bool TerminalUserSign(int nUserId, const char *pUserName, const char *pFilePath, const char *pFileName);

	int IssueControl(int nIssueId, int nControlType);
	int VoteControl(int nVoteId, int nControlType);

	int VoteMsg(const char *pMsg, int nLen);
	int CenterControl(int nControlType);

	bool SendChatMessage(const char *pMessage);
	bool SendMeetingService(const char *pMessage);

	int DownLoadFile(const char *pSvrFilePath, const char *pSaveFilePath);
	int UpLoadFile(const char *pFilePath, const char *pFileName, int nFileType);

	int SendWbData(const char *pWbData, int nDataLen);
	int SendCommentData(const char *pWbData, int nDataLen);

	void HandleRecvWbData(const char *pWbData, int nDataLen);
	void HandleRecvCommentData(const char *pWbData, int nDataLen);

	int UpdataFileInfo(const char *pFilePath, int nFileLen);
	void SetCmdChannelIsOk(void);

	bool SendExtendData(const char *pMessage);

protected:
	virtual void ThreadProcMain(void);

private:
	void HandleRecvData(RecvDataInfo *pRecv);
	void HandleMeetingIssued(RecvDataInfo *pRecv);

public:
	bool				m_bFileServerValid;
	OnMessageCallback	m_pCallback;

private:
	bool				m_bExit;
	int					m_nTerminalId;

	CMediaChannel		*m_pMedia;
	CCmdChannel			*m_pCmd;

	ListPtr				m_lstRecvData;
	CLock				m_lockRecvData;

	char				m_szSvrIP[16];
	unsigned short      m_usPort;

	
	MeetingInfo			m_stMeetingInfo;	

	map<string, UploadFileInfo *> m_lstSendFile;
	bool				m_bFirstConnect;
};
#endif
